package com.tvunetworks.center.device.controller.feign;

import com.tvunetworks.center.common.feign.matrix.DeviceGcsFeignInterface;
import com.tvunetworks.center.common.model.param.PeerIdParam;
import com.tvunetworks.center.common.model.param.matrix.AddUserDeviceParam;
import com.tvunetworks.center.common.model.param.matrix.UpdateMatrixNameParam;
import com.tvunetworks.center.common.model.vo.matrix.UserPostionFlag;
import com.tvunetworks.center.common.util.Result;
import com.tvunetworks.center.common.util.ResultUtil;
import com.tvunetworks.center.device.service.MyDeviceService;
import com.tvunetworks.center.gs.model.Device;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @program: tvucc-aggregator
 * @description: DeviceMatrixFeignController
 * @author lebronchen
 * @create: 2020-06-02 16:44
 **/
@RestController
@RequestMapping("/feign/gcs/device")
@Slf4j
public class DeviceGcsFeignController implements DeviceGcsFeignInterface {

    @Autowired
    private MyDeviceService myDeviceService;

    @Override
    public Result<String> addDevice(@RequestBody @Valid Device device) {
        if ( StringUtils.isBlank(device.getPeerId())) {
            return ResultUtil.paramErrorInfo();
        }
        myDeviceService.addDevice(device);
        return ResultUtil.success();
    }

    @Override
    public Result<String> updateDevice(@RequestBody @Valid UpdateMatrixNameParam param) {
        myDeviceService.updateDevice(param);
        return ResultUtil.success();
    }

    @Override
    public Result<String> deleteDevice(@RequestBody @Valid PeerIdParam param) {
        myDeviceService.deleteDevice(param.getPeerId());
        return ResultUtil.success();
    }

    @Override
    public Result<String> deleteDeviceWithSource(@RequestBody @Valid PeerIdParam param) {
        myDeviceService.deleteDeviceWithSource(param.getPeerId());
        return ResultUtil.success();
    }

    @Override
    public List<UserPostionFlag> listUserPostionFlag(@RequestBody @Valid PeerIdParam param) {
        return myDeviceService.listUserPostionFlag(param.getPeerId());
    }

    @Override
    public Result<String> addUserDevice(@RequestBody @Valid AddUserDeviceParam param) {
        myDeviceService.addUserDevice(param);
        return ResultUtil.success();
    }
}
